Optimize context usage for get_files in pull_request_read#2059
Merged
tommaso-moro merged 2 commits intomainfrom Feb 23, 2026
Merged
Optimize context usage for get_files in pull_request_read#2059tommaso-moro merged 2 commits intomainfrom
get_files in pull_request_read#2059tommaso-moro merged 2 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes context/token usage for the get_files method in the pull_request_read tool by introducing a new MinimalPRFile type that reduces payload size compared to the full github.CommitFile type. The change follows the established pattern in the codebase of using minimal types (similar to MinimalIssue, MinimalPullRequest, MinimalCommitFile, etc.) to reduce token consumption while preserving essential information.
Changes:
- Introduced
MinimalPRFiletype with essential PR file fields (filename, status, additions, deletions, changes, patch, previous_filename) - Added
convertToMinimalPRFilesconversion function to transform GitHub API responses to the minimal type - Updated
GetPullRequestFilesto use the new minimal type andMarshalledTextResulthelper - Updated test expectations to validate the minimal type output
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/github/minimal_types.go | Added MinimalPRFile type and convertToMinimalPRFiles conversion function |
| pkg/github/pullrequests.go | Updated GetPullRequestFiles to use minimal type conversion |
| pkg/github/pullrequests_test.go | Updated test to validate MinimalPRFile output instead of full CommitFile |
omgitsads
approved these changes
Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: https://github.com/github/copilot-mcp-core/issues/1309
Summary
This PR reduces the context window usage when listing pull request files using the
pull_request_readtool (get_pull_request_files).It does so by using the minimal types pattern (which is already used elsewhere in the codebase for the same reason) to reduce the payload that is sent back to the model when the tool is used. Specifically, irrelevant URL fields are removed and pointer-wrapped primitives are flattened to value types, eliminating unnecessary JSON noise per file entry.
Tests & Metrics
When tested with this PR:
Before: 6125 tokens
After: 5077 tokens
Context reduction: 17.11%
Fields preserved
filename,status,additions,deletions,changes,patch,previous_filenameFields dropped
sha(blob SHA, not useful for reasoning),blob_url,raw_url,contents_url(API URL strings, never used by models)Why
The full
github.CommitFilepayload returned by the GitHub API includes several fields that are irrelevant for model reasoning — most notably three API URL strings (blob_url,raw_url,contents_url) and a blobshaper file. These add up quickly for PRs with many changed files and waste context window on every call. Additionally, the raw Go types use pointer-wrapped primitives (*string,*int) which produce noisier JSON than plain value types.What changed
MinimalPRFiletype tominimal_types.go, following the existingMinimalCommitFile/MinimalPullRequestpattern — includespatchandprevious_filenamewhich are relevant for PR file diffs but not present inMinimalCommitFileconvertToMinimalPRFilesconverter functionGetPullRequestFilesto return[]MinimalPRFileviaMarshalledTextResultinstead of rawjson.Marshal(files)MinimalPRFilefieldsMCP impact
Security / limits
Tool renaming
deprecated_tool_aliases.goNote: if you're renaming tools, you must add the tool aliases. For more information on how to do so, please refer to the official docs.
Lint & tests
./script/lint./script/testDocs